using System.Collections.Generic;
using Mono.Cecil;

namespace EzDeploy.Core
{
    public class AssemblyInfo
    {
        readonly string _name;
        readonly string _fullName;
        readonly string _version;
        readonly string _fullyQualifiedPath;

        readonly TargetRuntime _runtime;
        readonly ModuleKind _moduleKind;
        readonly VersionStatus _status;
        readonly Dictionary<string, string> _attributes;

        public string Name
        {
            get
            {
                return _name;
            }
        }

        public string FullName
        {
            get
            {
                return _fullName;
            }
        }

        public string Version
        {
            get
            {
                return _version;
            }
        }

        public string FullyQualifiedPath
        {
            get
            {
                return _fullyQualifiedPath;
            }
        }

        public TargetRuntime Runtime
        {
            get
            {
                return _runtime;
            }
        }

        public ModuleKind ModuleKind
        {
            get
            {
                return _moduleKind;
            }
        }

        public VersionStatus Status
        {
            get
            {
                return _status;
            }
        }

        public Dictionary<string, string> Attributes
        {
            get
            {
                return _attributes;
            }
        }

        public AssemblyInfo(AssemblyDefinitionComposite assemblyDefinitionComposite)
            : this(assemblyDefinitionComposite.Assembly, assemblyDefinitionComposite.AssemblyName, assemblyDefinitionComposite.Status)
        {
            _attributes = assemblyDefinitionComposite.Attributes;
        }

        private AssemblyInfo(AssemblyDefinition assembly, AssemblyNameReference assemblyName, VersionStatus status)
        {
            _name = assemblyName.Name;
            _fullName = assemblyName.FullName;
            _status = status;
            _version = assemblyName.Version.ToString();

            if (status != VersionStatus.Unknown)
            {
                _fullyQualifiedPath = assembly.MainModule.FullyQualifiedName;
                _runtime = assembly.MainModule.Runtime;
                _moduleKind = assembly.MainModule.Kind;
            }
            else
            {
                _fullyQualifiedPath = string.Format("({0}{1})", assemblyName.Name, _moduleKind == Mono.Cecil.ModuleKind.Dll? ".dll":".exe");
            }
        }
    }
}
